package com.itqf.controller;

import com.itqf.entity.Users;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Company: 千锋互联
 * @Author: 李丽婷
 * @Date: 2020/11/16
 * @Time: 下午3:29
 */
@Controller
//@RestController   @ResponseBody+@Controller
public class JsonController {


    @RequestMapping("/find")
    @ResponseBody  //返回值 --json  默认底层使用的是 jackson
    public Users  find(){
        Users users = new Users();//数据库查出来的
        users.setAge(18);
        users.setUsername("admin");
        users.setPassword("admin");
        users.setBirthdate(new Date());

        users.setSalary(18888.88888);

        return users;
    }

    // find?id=1&name=zhangsan

    //{"id":1,"name":"张三"}
    //  前端传过来的参数是json格式了？？？
    //@RequestBody  把前端传过来的json-->java对象
    @RequestMapping("/registerAction")
    @ResponseBody  //json数据  --->  @RequestBody
    public Map<String,Object> add(@RequestBody Users users){

        int i  = 10/0;

        System.out.println("--->转换的java对象是："+users);
        //service.add();
        Map<String,Object> map = new HashMap();
        map.put("code",0);
        map.put("msg","操作成功！！");
        map.put("data",users);

        return  map;
    }

    @RequestMapping("/registerAction1")
    @ResponseBody //  表单数据  直接用对象接  （小心日期问题）
    public Map<String,Object> add1(Users users){
        Map<String,Object> map = new HashMap();
        map.put("code",0);
        map.put("msg","操作成功！！");
        map.put("data",users);

        return  map;
    }





}
